﻿@{
    ViewBag.Title = "油卡充值信息";
    Layout = "~/Areas/IM/Views/Shared/_Layout.cshtml";
}
@section scripts{
    <script src="../Scripts/jquery.AnkeExtend.js"> </script>
    <script type="text/javascript">
    //页面动态改动
    $(window).resize(function () {
        $.setGridWithSearchBar("#TableForm", "#SearchBar", "#gridRecharge");
    });

    //页面初始化
    $(document).ready(function () {
        bindGrid();
        initListcombo();
        initcombo();
        DisableBackspace();
        $.setGridWithSearchBar("#TableForm", "#SearchBar", "#gridRecharge");
    })
    //#region 为Combobox增加--请选择--
    function EUIcombobox(jqS, o) {
        $.ajax({
            type: "POST",
            async: false,
            url: o.url,
            dataType: "JSON",
            success: function (data1, textStatus, jqXHR) {
                o.data = o.OneOption.concat(data1);
                delete o.url;
                delete o.OneOption;
                $(jqS).combobox(o);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert("获取字典数据失败！可能是已经超时，请重新登录！");
            }
        });
    }
    function initListcombo() {
        //取卡号
        $.EUIcombobox("#cardCode", {
            url: '@Url.Content("~/CM/CardInfo/GetCardCode?em=")' + '@ViewData["em"]' + '&selfCenterID=' + '@ViewData["selfCenterID"]' + '&selfStationID=' + '@ViewData["selfStationID"]' + '&selfWorkCode=' + '@ViewData["selfWorkCode"]',
            valueField: 'ID',
            textField: 'Name',
            editable: true,
            OneOption: [{
                ID: "",
                Name: "--请选择--"
            }]
        });
        EUIcombobox("#centerID", {
            url: '@Url.Content("~/Medical/GetCenter/")',
            valueField: 'ID',
            textField: 'Name',
            //prompt: '--请选择--',
            editable: false,
            OneOption: [{
                ID: "",
                Name: "--请选择--"
            }],
            onSelect: function (rec) {
                var urlstation = '@Url.Content("~/Medical/GetStation?code=")' + rec.ID;
                EUIcombobox("#stationID", {
                    url: urlstation,
                    valueField: 'ID',
                    textField: 'Name',
                    //prompt: '--请选择--',
                    editable: false,
                    OneOption: [{
                        ID: "",
                        Name: "--请选择--"
                    }]
                });
            }
        });
        //#endregion
        //#region 出车分站
        EUIcombobox("#stationID", {
            url: '@Url.Content("~/Medical/GetStation?code=")',
            valueField: 'ID',
            textField: 'Name',
            //prompt: '--请选择--',
            editable: false,
            OneOption: [{
                ID: "",
                Name: "--请选择--"
            }]
        })
        $('#start').datetimebox('setValue', '@ViewData["start"]');
        $('#end').datetimebox('setValue', '@ViewData["end"]');
    }

    function bindGrid() {
        $('#gridRecharge').datagrid({
            width: 'auto',
            height: 'auto',
            fitColumns: true,
            striped: true,
            singleSelect: true,
            url: '@Url.Content("~/CM/Recharge/DataLoad")',
            loadMsg: '数据加载中请稍后……',
            pagination: true,//启用分页
            rownumbers: true,//显示页码
            pageSize: 15,//设置 页容量
            pageList: [10, 15, 20],//设置 页容量下拉框
            queryParams: {
                start: $('#start').datetimebox('getValue'),
                end: $('#end').datetimebox('getValue'),
                center: $("#centerID").combobox('getValue'),
                station: $('#stationID').combobox('getValue'),
                cardCode: $('#cardCode').combobox('getText'),
                invoiceNumber: $('#invoiceNumber').textbox('getText')
            },
            columns: [[
               { title: 'ID', field: 'ID', hidden: true },
               { title: '分中心', field: 'Center', width: '6%', align: "center", sortable: false },
               { title: '分站', field: 'Station', width: '7%', align: "center", sortable: false },
               { title: '分中心编码', field: 'CenterID', hidden: true },
               { title: '分站编码', field: 'StationID', hidden: true },
               { title: '卡号', field: 'CardCode', width: '14%', align: "center", sortable: false },
               { title: '油卡负责人工号', field: 'DriverWorkID', width: '8%', align: "center", sortable: false },
               { title: '油卡负责人姓名', field: 'DriverName', width: '8%', align: "center", sortable: false },
               { title: '卡内余额', field: 'Remaining', width: '6%', align: "center", sortable: false },
               { title: '充值金额', field: 'RechargeAmount', width: '6%', align: "center", sortable: false },
               { title: '卡内金额', field: 'CardAmount', width: '6%', align: "center", sortable: false },
               { title: '充值日期', field: 'RechargeTime', width: '13%', align: "center", sortable: false },
               { title: '操作人', field: 'FillPerson', width: '8%', align: "center", sortable: false, hidden: true },
               { title: '发票编号', field: 'FPCode', width: '13%', align: "center", sortable: false },
               { title: '备注', field: 'Remark', width: '12%', align: "center", sortable: false }
            ]],
            toolbar: [
                {
                    id: 'btnAdd',
                    text: '新增',
                    iconCls: 'icon-add',
                    handler: function () {
                        $('#NewRechargeList').dialog('open');
                        initAddInfo();
                        if ('@ViewData["RolePermissionEdit"]' == "Edit") {
                            $("#Remaining").numberbox({ disabled: false });
                        }
                    }
                }, '-',
               {
                   id: 'btnEdit',
                   text: '修改',
                   iconCls: 'icon-edit',
                   handler: function () {
                       var row = $('#gridRecharge').datagrid('getSelected');
                       if (row) {
                           initUpdateInfo(row);
                           $("#ID").val(row.ID);
                           $("#CardCode").combobox("setValue", row.CardCode);
                           $("#Center").combobox("setText", row.Center);
                           $("#Station").combobox("setText", row.Station);
                           $("#DriverWorkID").combobox("setText", row.DriverWorkID);
                           $("#DriverName").combobox("setText", row.DriverName);
                           $("#RechargeTime").datetimebox("setText", row.RechargeTime);
                           $("#Remaining").numberbox("setValue", row.Remaining);
                           $("#RechargeAmount").numberbox("setValue", row.RechargeAmount);
                           $("#CardAmount").numberbox("setValue", row.CardAmount);
                           $("#FPCode").textbox("setText", row.FPCode);
                           $("#Remark").textbox("setText", row.Remark);
                           $("#Remaining").numberbox({ disabled: false });
                           $('#NewRechargeList').dialog('open');
                       } else {
                           $.messager.alert('提示', '请选择数据行', 'info', function () {
                           });
                       }
                   }
               }
            ]
        })
        $.setGridWithSearchBar("#TableForm", "#SearchBar", "#gridRecharge");
        if ('@ViewData["em"]' == 'ALL') {
            if ('@ViewData["RolePermissionInsert"]' == "Insert") {
                $('div.datagrid-toolbar a').eq(0).show();
                $('div.datagrid-toolbar div').eq(0).show();
            } else if ('@ViewData["RolePermissionInsert"]' != "Insert") {
                $('div.datagrid-toolbar a').eq(0).hide();
                $('div.datagrid-toolbar div').eq(0).hide();
            }
        } else if ('@ViewData["em"]' == 'CENTER') {
            if ('@ViewData["RolePermissionInsert"]' == "Insert") {
                $('div.datagrid-toolbar a').eq(0).show();
                $('div.datagrid-toolbar div').eq(0).show();

            } else if ('@ViewData["RolePermissionInsert"]' != "Insert") {
                $('div.datagrid-toolbar a').eq(0).hide();
                $('div.datagrid-toolbar div').eq(0).hide();

            }
        } else if ('@ViewData["em"]' == 'STATION' || '@ViewData["em"]' == 'SELF') {
                $('div.datagrid-toolbar a').eq(0).hide();
                $('div.datagrid-toolbar div').eq(0).hide();
        }
        if ('@ViewData["RolePermissionEdit"]' == "Edit") {
                    $('div.datagrid-toolbar a').eq(1).show();
                    $('div.datagrid-toolbar div').eq(1).show();
                } else if ('@ViewData["RolePermissionEdit"]' != "Edit") {
                    $('div.datagrid-toolbar a').eq(1).hide();
                    $('div.datagrid-toolbar div').eq(1).hide();
                }
    }
    //查询
    function reSearch() {
        $('#gridRecharge').datagrid({
            pageNumber: 1,
            queryParams: {
                start: $('#start').datetimebox('getValue'),
                end: $('#end').datetimebox('getValue'),
                center: $("#centerID").combobox('getValue'),
                station: $('#stationID').combobox('getValue'),
                cardCode: $('#cardCode').combobox('getText'),
                invoiceNumber: $('#invoiceNumber').textbox('getText')
            }
        });
         if ('@ViewData["em"]' == 'ALL') {
            if ('@ViewData["RolePermissionInsert"]' == "Insert") {
                $('div.datagrid-toolbar a').eq(0).show();
                $('div.datagrid-toolbar div').eq(0).show();
            } else if ('@ViewData["RolePermissionInsert"]' != "Insert") {
                $('div.datagrid-toolbar a').eq(0).hide();
                $('div.datagrid-toolbar div').eq(0).hide();
            }
        } else if ('@ViewData["em"]' == 'CENTER') {
            if ('@ViewData["RolePermissionInsert"]' == "Insert") {
                $('div.datagrid-toolbar a').eq(0).show();
                $('div.datagrid-toolbar div').eq(0).show();

            } else if ('@ViewData["RolePermissionInsert"]' != "Insert") {
                $('div.datagrid-toolbar a').eq(0).hide();
                $('div.datagrid-toolbar div').eq(0).hide();

            }
        } else if ('@ViewData["em"]' == 'STATION' || '@ViewData["em"]' == 'SELF') {
            $('div.datagrid-toolbar a').eq(0).hide();
            $('div.datagrid-toolbar div').eq(0).hide();

        }
        if ('@ViewData["RolePermissionEdit"]' == "Edit") {
            $('div.datagrid-toolbar a').eq(1).show();
            $('div.datagrid-toolbar div').eq(1).show();
        } else if ('@ViewData["RolePermissionEdit"]' != "Edit") {
            $('div.datagrid-toolbar a').eq(1).hide();
            $('div.datagrid-toolbar div').eq(1).hide();
        }
    }
    </script>
}
<div id="TableForm" class="easyui-layout" style="width:auto; height: auto; margin-left: auto; margin-right: auto">
    <div data-options="region:'center',title:'油卡充值信息',iconCls:'icon-custom-Entry'">
        <div id="SearchBar" data-options="region:'center'" style="overflow: hidden; padding: 10px">
            <table style="width:99%" cellpadding="0" cellspacing="5" border="0">
                <tr>
                    <td align="right" valign="middle" width="8%">充值时间：</td>
                    <td align="right" valign="middle" width="12%">
                        <input id="start" class="easyui-datetimebox" value=@ViewData["start"] style="width:160px" data-options="editable:false" />
                    </td>
                    <td align="right" valign="middle" width="8%">至：</td>
                    <td align="right" valign="middle" width="12%">
                        <input id="end" class="easyui-datetimebox" value=@ViewData["end"] style="width:150px" data-options="editable:false" />
                    </td>
                    <td align="right" valign="middle" width="8%">分中心：</td>
                    <td align="right" valign="middle" width="12%">
                        <input id="centerID" class="easyui-combobox" style="width:150px" data-options="panelHeight:'auto', editable:false" />
                    </td>
                    <td align="right" valign="middle" width="8%">分站：</td>
                    <td align="right" valign="middle" width="12%">
                        <input id="stationID" class="easyui-combobox" style="width:150px" />
                    </td>
                </tr>
                <tr>
                    <td align="right" valign="middle" width="8%">卡号：</td>
                    <td align="right" valign="middle" width="12%">                       
                        <input id="cardCode" class="easyui-combobox" style="width:160px" />
                    </td>
                    <td align="right" valign="middle" width="8%">发票编号：</td>
                    <td align="right" valign="middle" width="12%">
                        <input id="invoiceNumber" class="easyui-textbox" style="width:150px" />
                    </td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td align="center" valign="middle" width="11%">
                        <a href="javascript:void(0)" id="btnsearch" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="reSearch()">查询</a>
                    </td>
                </tr>
            </table>
        </div>
        <div data-options="region:'center'" style="background: #fafafa; overflow: hidden">
            <table id="gridRecharge"></table>
        </div>
    </div>
</div>

@Html.Partial("~/Areas/CM/Views/Recharge/RechargeEdit.cshtml")